package com.cater.talents.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.cater.annotation.SystemControllerLog;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.talents.entity.TalentsWorkExperienceResource;
import com.cater.talents.service.TalentsWorkExperienceResourceServiceImpl;

/**
* 描述：教育经历采集控制层
* @author yong
* @date 2018/09/29
*/
@Controller
@RequestMapping("/talentsWorkExperienceResource")
public class TalentsWorkExperienceResourceController {

	@Autowired
	private TalentsWorkExperienceResourceServiceImpl service;

	/**
	 * @教育经历采集管理列表视图
	 * @return
	 */
	@RequestMapping("/list")
	public String list() {
		return "talents/talentsWorkExperienceResource/list";
	}

	/**
	 * @教育经历采集管理数据分页
	 * @param query
	 * @param request
	 * @return
	 */
	@RequestMapping("listData")
	@ResponseBody
	@SystemControllerLog(description = "查询教育经历采集分页数据")
	public PageResult<TalentsWorkExperienceResource> listData(CommonQuery query, HttpServletRequest request) {
		PageResult<TalentsWorkExperienceResource> result = service.findPageResult(query);
		return result;
	}

	/**
	 * 添加视图
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "addView")
	@RequiresPermissions("talentsWorkExperienceResource:add")
	public String addView() {
		return "talents/talentsWorkExperienceResource/add";
	}

	/**
	 * 添加操作
	 * 
	 * @param t
	 * @return
	 */
	@RequestMapping(value = "add")
	@RequiresPermissions("talentsWorkExperienceResource:add")
	@ResponseBody
	@SystemControllerLog(description = "添加教育经历采集")
	public JSONObject add(TalentsWorkExperienceResource t, CommonQuery query) {
		JSONObject json = new JSONObject();
			String id = service.saves(t);
			if (StringUtils.isNotBlank(id)) {
				json.put("code", 200);
				json.put("message", "success");
			} else {
				json.put("code", 999);
				json.put("message", "fail");
			}
		return json;
	}

	/**
	 * 修改视图
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "editView")
	@RequiresPermissions("talentsWorkExperienceResource:edit")
	public String editView(String id, Model model, CommonQuery query) {
		TalentsWorkExperienceResource t = service.getById(id);
		model.addAttribute("talentsWorkExperienceResource", t);
		return "talents/talentsWorkExperienceResource/update";
	}

	/**
	 * 修改操作
	 * 
	 * @param t
	 * @return
	 */
	@RequestMapping(value = "update")
	@RequiresPermissions("talentsWorkExperienceResource:edit")
	@ResponseBody
	@SystemControllerLog(description = "修改教育经历采集")
	public JSONObject update(TalentsWorkExperienceResource t, CommonQuery query) {
		JSONObject json = new JSONObject();
		try {
			service.update(t);
			json.put("code", 200);
			json.put("message", "修改成功");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 999);
			json.put("message", "修改失败");
		}
		return json;
	}

	/**
	 * 删除操作
	 * 
	 * @param id
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/delete")
	@RequiresPermissions("talentsWorkExperienceResource:delete")
	@SystemControllerLog(description = "删除教育经历采集")
	public JSONObject delete(String id) {
		JSONObject json = new JSONObject();
		try {
			service.delete(id);
			json.put("code", 200);
			json.put("message", "删除成功");
		} catch (Exception e) {
			e.printStackTrace();
			json.put("code", 999);
			json.put("message", "删除失败");
		}
		return json;
	}
	
	/**
	 * 查看视图
	 * 
	 * @param model
	 * @return
	 */
	@RequestMapping(value = "detailView")
	@RequiresPermissions("talentsWorkExperienceResource:detail")
	public String detailView(String id, Model model, CommonQuery query) {
		TalentsWorkExperienceResource t = service.getById(id);
		model.addAttribute("talentsWorkExperienceResource", t);
		return "talents/talentsWorkExperienceResource/detail";
	}


}